//////////////////////////////////////////////////////////////////////
////                                                              ////
////  StatusAndReset.v                                            ////
////                                                              ////
////                                                              ////
////  This file is part of the "Pico E12" project                 ////
////                                                              ////
////                                                              ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
////                                                              ////
//// Copyright (C) 2006, Pico Computing, INC.                     ////
//// http://www.picocomputing.com                                 ////
////                                                              ////
//// This source file may be used and distributed without         ////
//// restriction provided that this copyright statement is not    ////
//// removed from the file and that any derivative work contains  ////
//// the original copyright notice and the associated disclaimer. ////
////                                                              ////
//// This source file is free software; you can redistribute it   ////
//// and/or modify it under the terms of the GNU Lesser General   ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any   ////
//// later version.                                               ////
////                                                              ////
//// This source is distributed in the hope that it will be       ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
//// PURPOSE.  See the GNU Lesser General Public License for more ////
//// details.                                                     ////
////                                                              ////
//// You should have received a copy of the GNU Lesser General    ////
//// Public License along with this source; if not, download it   ////
//// from http://www.opencores.org/lgpl.shtml                     ////
////                                                              ////
////////////////////////////////////////////////////////////////////RT


`include "PicoDefines.v"

module StatusAndReset
  (input          IORead,
   input          IOWrite,
   input [`PCMCIA_ADR_LINES-1:1] IOAddress,
   input [15:0]   DataIn,
   output [15:0]  DataOut,
   input          FLASH_BUSY,
   output         FLASH_RESET,
   input          DcmsLocked,
   input          BackplaneDetected);

wire ResetWrite;

assign ResetWrite = (IOWrite) && (IOAddress[`PCMCIA_ADR_LINES-1:1] == `PICOPORT_RESET_PPC);

assign DataOut[15:0] = (IORead == 1'b1) ? ((IOAddress[`PCMCIA_ADR_LINES-1:1] == `STATUS_ADDRESS) ? ((DcmsLocked  ? `STATUS_DCMS_LOCKED : 0) |
                                                                                                    (FLASH_BUSY  ? `STATUS_FLASH_READY : 0) |
                                                                                                    (BackplaneDetected  ? `STATUS_BACKPLANE_DETECTED  : 0)) :
                                          ((IOAddress[`PCMCIA_ADR_LINES-1:1] == `MAGIC_NUM_ADDR) ? `PICO_MAGIC_NUM :
                                          16'h0)) : 16'h0;

assign FLASH_RESET = ~((ResetWrite) && (DataIn[15:0] == `FLASH_RESET_PASSWORD));

endmodule
